package com.accp.biz.impl;

import java.util.List;
import com.accp.biz.EmailBiz;
import com.accp.dao.EmailDao;
import com.accp.pojo.Email;


public class EmailBizImpl implements EmailBiz {
	private EmailDao emailDao;
	
	public void setEmailDao(EmailDao emailDao) {
		this.emailDao = emailDao;
	}
	/**
	 * 获取收件人列表
	 */
	@Override
	public List<String> recipientsList() {
		List<String> list = emailDao.recipientsList();
		return list;
	}
	/**
	 * 添加（发送）邮件
	 */
	@Override
	public boolean add(Email email) {
		if(emailDao.add(email)){
			return true;
		}else{
			return false;
		}	
	}

	/**
	 * 查收邮件
	 */
	public List<Email> findByUserName(String userName) {
		List<Email> list = emailDao.findByUserName(userName);
		return list;
	}
	/**
	 * 删除邮件
	 */
	@Override
	public boolean delete(Email email) {
		boolean flag = false;
		if(email.getIsDeleted()==1){
			email.setIsDeleted(0);
			emailDao.delete(email);
			flag = true;
		}
		return flag;
	}
	/**
	 * 彻底删除邮件
	 */
	@Override
	public boolean deleteReal(Email email) {
		boolean flag = false;
		if(email.getIsDeleted()==0){
			emailDao.deleteReal(email);
			flag = true;
		}
		return flag;
	}

	/**
	 * 查询垃圾邮件
	 */
	@Override
	public List<Email> spamList(String nickName) {
		List<Email> list = emailDao.spamList(nickName);
		return list;
	}
	/**
	 * 通过id查看邮件信息
	 */
	@Override
	public Email findById(Integer id) {
		return emailDao.findById(id);
	}
	/**
	 * 修改邮件读取状态
	 */
	@Override
	public boolean updateIsRead(Email email) {
		return emailDao.updateIsRead(email);
	}
	/**
	 * 还原邮件
	 */
	@Override
	public boolean updateIsDeleted(Email email) {
		return emailDao.updateIsDeleted(email);
	}
	/**
	 * 分页查询
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public List selectByPage(String className, int pageNo, int pageSize,String userName) {
		List list = emailDao.selectByPage(className, pageNo, pageSize,userName);
		return list;
	}
	/**
	 * 查看下一页
	 */
	@Override
	public int searchRecordsNextPage(int pageSize, String className,String userName) {
		int total = emailDao.totalPage(className,userName);
		int pageNo = total / pageSize;
		if(total % pageSize > 0){
			pageNo++;
		}
		return pageNo;
	}
	
}
